<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Compose_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 根据商品ID得到组成信息
	 */
	public function find_by_product($productid){
		$this->db->select('t_compose.id,t_compose.materialid,t_compose.amount,t_nutrition.name');
		$this->db->from('t_compose');
		$this->db->join('t_nutrition', 't_compose.materialid = t_nutrition.id','left');
		$this->db->where('productid',$productid);
		$query = $this->db->get();
		return $query->result_array();
	}
	/*
	 * 添加组成信息
	 */
	public function create($compose){
		$this->db->insert('t_compose', $compose);
		return $this->db->insert_id();
	}
	/*
	 * 删除组成信息
	 */
	public function delete($id){
		$this->db->where('id', $id);
		$this->db->delete('t_compose');
		return $this->db->affected_rows()>0;
	}
}
